package h_10_27;

/**
 * 209. 长度最小的子数组
 * https://leetcode.cn/problems/minimum-size-subarray-sum/description/
 */
public class Main4 {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = 0;
        int ret = Integer.MAX_VALUE;
        int sum = 0;
        while(right < n) {
            int in = nums[right];
            sum += in;

            while(sum >= target) {
                ret = Math.min(ret,right - left + 1);
                sum -= nums[left++];
            }

            right++;
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }
}
